#include <bits/stdc++.h>

using namespace std;

priority_queue <int, vector<int>, greater<int> > pq; //小根堆
//小根堆必须写齐3个参数
//大根堆则无所谓

int main(){
    int n;
    cin >> n;
    int x;
    for(int i = 1; i <= n; i++){
        cin >> x;
        pq.push(x);
    }
    int ans = 0;
    while(pq.size() > 1){ //!pq.empty()
        int t1 = pq.top();  pq.pop();
        int t2 = pq.top();  pq.pop();
        pq.push(t1 + t2);
        ans += (t1 + t2);
    }
    cout << ans;
    return 0;
}